package com.cz;

import java.io.IOException;
import java.net.URI;
import java.util.HashMap;

import org.apache.log4j.PropertyConfigurator;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.servlet.GrizzlyWebContainerFactory;

/**
 * Main class.
 *
 */
public class Main {
    
    public static final int OAUTH_PORT = 10087;
//    public static final String OAUTH_URI = "http://127.0.0.2:%d/uus/";
    public static final String OAUTH_URI = "http://192.168.19.75:%d/oauth/";

    /**
     * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
     * @return Grizzly HTTP server.
     * @throws IOException 
     * @throws IllegalArgumentException 
     */
    public static HttpServer startOauthServer(int port) throws IllegalArgumentException, IOException {
    	
    	final HashMap<String, String> initParams = new HashMap<String, String>();
    	initParams.put("jersey.config.server.provider.packages", "org.apache.oltu.oauth2.integration.endpoints");
    	
        return GrizzlyWebContainerFactory.create(URI.create(String.format(OAUTH_URI, port)),initParams);
    }

    /**
     * Main method.
     * @param args
     * @throws IOException
     */
    @SuppressWarnings("deprecation")
	public static void main(String[] args) throws IOException {
        PropertyConfigurator.configure("conf/log4j.properties");
        int oauthPort = OAUTH_PORT;

        final HttpServer oauthServer = startOauthServer(oauthPort);
        String oauthUri = String.format(OAUTH_URI, OAUTH_PORT);
        System.out.println(String.format("Oauth Server started... enter to stop it...", oauthUri));

        System.in.read();
        oauthServer.stop();
    }
}

